package com.qf.dao.impl;

import com.qf.dao.AdminDao;
import com.qf.domain.User;
import com.qf.util.DataSourceUtils;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;

import java.sql.SQLException;

/**
 * @author Administrator
 * @version v1.0
 * @date 2022/4/21
 */
public class AdminDaoImpl implements AdminDao {
    private QueryRunner queryRunner = new QueryRunner(DataSourceUtils.getDatasource());
    @Override
    public User selectByUsernameAndPassword(String username, String password) {
        String sql = "SELECT `id`,`username`,`password`,`email`,`gender`,`flag`,`role`,`code` FROM `tb_user` WHERE `username` = ? and password =md5(?) and role = 0;";
        try {
            return   queryRunner.query(sql,new BeanHandler<>(User.class),username,password);
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }
}
